package com.zsj.common_base.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author 郑声军
 * @Date 2021/12/26 19:43
 * 时间注入
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        //这里的值是属性名称而不是字段名称
        this.setFieldValByName("create_time",new Date(),metaObject);
        this.setFieldValByName("destroy_time",new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("destroy_time",new Date(),metaObject);
    }
}
